#pragma once

#include <iostream>
#include <cstdarg>
#include <cstdio>
#include <string>

#define NORMAL  0
#define DEBUG   1
#define WARNING 2
#define ERROR   3
#define FATAL   4

using namespace std;

string getstr(int type)
{
    switch(type)
    {  
        case(DEBUG):
            return "DEBUG";
        case(WARNING):
                return "WARNING";
        case(ERROR):
            return "ERROR";
        case(FATAL):
            return "FATAL";
        default:
            return "NORMAL";
    }
}

void log(int type, const char *format, ...)
{
    // 输出格式：[类型] 错误信息
    char prefix[1024];
    string typestr = getstr(type);
    snprintf(prefix, sizeof(prefix), "[%s]", typestr.c_str());

    va_list arg;
    va_start(arg, format);

    char message[1024];
    vsnprintf(message, sizeof(message), format, arg);

    cout << prefix << " " << message << endl;
}